@extends('layout.master')

@section('title','安全密码确认')

@section('css')
    @parent
    <!-- animation CSS -->
    <link href="{{ asset('css/animate.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/icheck/skins/all.css') }}" rel="stylesheet">
    <link href="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.css') }}" rel="stylesheet">
@endsection
@section('main')
    <div class="center-block" style="width: 98%;max-width:600px;margin-top: 100px">
        <div class="portlet light portletLight">
            <div class="portlet-title portletTitle">
                <div class="caption caption-md">
                    <i class="icon-bar-chart theme-font hide portletTitleColor"></i>
                    <span class="caption-subject font-blue-madison bold uppercase portletTitleColor">请输入安全密码</span>
                </div>
            </div>
            <div class="portlet-body">
                <form class="form-horizontal" role="form" method="post">
                    <div class="form-group">
                        <label for="password" class="col-md-3 control-label">安全密码</label>
                        <div class="col-md-8">
                            <input type="password" class="form-control" id="password" name="password">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-offset-3 col-md-10">
                            {!! csrf_field() !!}
                            <button type="submit" id="entryguard" class="btn btn-primary">确认</button>
                            <a type="button" href="{{ url('/') }}" class="btn btn-danger">返回个人中心</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- jQuery file upload -->
    <script src="{{ asset('plugins/bower_components/dropify/dist/js/dropify.min.js') }}"></script>
    <script>
        $(document).ready(function () {
            // Basic
            $('.dropify').dropify();
        });
    </script>
    <script src="{{ asset('plugins/bower_components/bootstrap-select/bootstrap-select.min.js') }}"
            type="text/javascript"></script>
    <!-- bt-switch -->
    <script src="{{ asset('plugins/bower_components/bootstrap-switch/bootstrap-switch.min.js') }}"></script>

    <!-- Magnific popup JavaScript -->
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup.min.js') }}"></script>
    <script src="{{ asset('plugins/bower_components/Magnific-Popup-master/dist/jquery.magnific-popup-init.js') }}"></script>


    <script>
        $('#entryguard').click(function (e) {

            e.preventDefault();
            //1.
            var password = $('#password').val();
            if (!password) {
                toasterror('请输入安全密码');
                return false;
            }
            // 2
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: '/entryguard',
                type: 'POST',
                data: {'password': password},
                success: function (data) {
                    if (data.status !== 1) {
                        toasterror(data.message);
                    } else {
                        window.location.href = data.message;
                    }
                },
                error: function (e) {
                    $('img').click();
                    if (e.readyState === 4 && e.status === 422) {
                        for (var i in e.responseJSON) {
                            if (e.responseJSON[i] !== 'The given data was invalid.') {
                                err = e.responseJSON[i];
                                for (var j in err) {
                                    toasterror(err[j][0]);
                                }
                            }
                        }
                    }
                }
            })
        });
    </script>
@endsection